package search

import (
	"github.com/gin-gonic/gin"
	"organoid_public/global"
	"organoid_public/pkg/logger"
)

type handler struct {
	svc *service
	log logger.Logger
}

func newHandler(log logger.Logger) (*handler, error) {
	svc, err := newService(log)
	if err != nil {
		return nil, err
	}

	return &handler{
		svc: svc,
		log: log,
	}, nil
}

// GetOrganoidList 获取搜索类器官培养列表
func (h *handler) GetOrganoidList(c *gin.Context) {
	var (
		response = global.Response.New(c)
		params   OrganoidListReq
		err      error
	)
	err = response.BindQueryWithValidate(&params)
	if err != nil {
		return
	}

	data, err := h.svc.GetOrganoidList(&params)
	if err != nil {
		response.Error(err).ToJSON()
		return
	}

	response.Success(data).ToJSON()
}

// GetCoCultureList 获取搜索共培养列表
func (h *handler) GetCoCultureList(c *gin.Context) {
	var (
		response = global.Response.New(c)
		params   OrganoidListReq
		err      error
	)
	err = response.BindQueryWithValidate(&params)
	if err != nil {
		return
	}

	data, err := h.svc.GetCoCultureList(&params)
	if err != nil {
		response.Error(err).ToJSON()
		return
	}

	response.Success(data).ToJSON()
}

// GetBioMarkerIdentifyList 获取搜索已确定的生物标志物列表
func (h *handler) GetBioMarkerIdentifyList(c *gin.Context) {
	var (
		response = global.Response.New(c)
		params   BiomarkerListReq
		err      error
	)
	err = response.BindQueryWithValidate(&params)
	if err != nil {
		return
	}

	data, err := h.svc.GetBioMarkerIdentifyList(&params)
	if err != nil {
		response.Error(err).ToJSON()
		return
	}

	response.Success(data).ToJSON()
}

// GetBioMarkerPotentialList 获取搜索潜在的生物标志物列表
func (h *handler) GetBioMarkerPotentialList(c *gin.Context) {
	var (
		response = global.Response.New(c)
		params   BiomarkerListReq
		err      error
	)
	err = response.BindQueryWithValidate(&params)
	if err != nil {
		return
	}

	data, err := h.svc.GetBioMarkerPotentialList(&params)
	if err != nil {
		response.Error(err).ToJSON()
		return
	}

	response.Success(data).ToJSON()
}
